//package com.amumu.drama.common.moudles.sumapay.servlet;
//
//import com.amumu.drama.common.moudles.sumapay.tools.MD5Tools;
//import com.amumu.drama.common.moudles.sumapay.tools.MySSLHostnameVerifier;
//import com.amumu.drama.common.moudles.sumapay.tools.MyX509TrustManager;
//import org.apache.http.HttpStatus;
//import org.apache.http.NameValuePair;
//import org.apache.http.client.HttpClient;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.impl.client.HttpClientBuilder;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.util.EntityUtils;
//
//import javax.net.ssl.HostnameVerifier;
//import javax.net.ssl.SSLContext;
//import javax.net.ssl.TrustManager;
//import javax.net.ssl.X509TrustManager;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//
//
//public class IZZ5000_Servlet extends HttpServlet {
//	/**
//	 *
//	 */
//	private static final long serialVersionUID = 1L;
//
//	/*
//	 * public static void main(String[] args) throws IOException, URISyntaxException
//	 * { httpPost(); }
//	 */
//	@Override
//	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//		doPost(request, response);
//	}
//
//	@Override
//	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.setContentType("text/html;charset=GBK");
//		request.setCharacterEncoding("GBK");
//		response.setCharacterEncoding("GBK");
//		PrintWriter out = response.getWriter();
//		try {
//			// 得到AgreementPaySend，并获取跳转url
//			String requestId = request.getParameter("requestId");
//			String originalRequestId = request.getParameter("originalRequestId");
//			String tradeProcess = request.getParameter("tradeProcess");
//			String fund = request.getParameter("fund");
//			String noticeUrl = request.getParameter("noticeUrl");
//			String remark = request.getParameter("remark");
//			String merKey = request.getParameter("merKey");
//			String reason = request.getParameter("reason");
//			String refundMothed = request.getParameter("refundMothed");
//
//			StringBuilder sb = new StringBuilder();
//			sb.append(requestId);
//			sb.append(originalRequestId);
//			sb.append(tradeProcess);
//			sb.append(fund);
//			sb.append(noticeUrl);
//			sb.append(remark);
//			String mersignature = MD5Tools.Md5(sb.toString(), merKey);
//			List<NameValuePair> nvps = new ArrayList<NameValuePair>();
//
//			nvps.add(new BasicNameValuePair("requestId", requestId));
//			nvps.add(new BasicNameValuePair("originalRequestId", originalRequestId));
//			nvps.add(new BasicNameValuePair("tradeProcess", tradeProcess));
//			nvps.add(new BasicNameValuePair("fund", fund));
//			nvps.add(new BasicNameValuePair("noticeUrl", noticeUrl));
//			nvps.add(new BasicNameValuePair("remark", remark));
//			nvps.add(new BasicNameValuePair("reason", reason));
//			nvps.add(new BasicNameValuePair("refundMothed", refundMothed));
//			nvps.add(new BasicNameValuePair("mersignature", mersignature));
//			System.out.println(mersignature + "=mersignature");
//
//			SSLContext sslContext = null;
//
//			sslContext = SSLContext.getInstance("TLSv1.2");
//
//			X509TrustManager tm = new MyX509TrustManager();
//			sslContext.init(null, new TrustManager[] { tm }, new java.security.SecureRandom());
//
//			HttpClientBuilder httpClientBuilder = HttpClients.custom().setSSLContext(sslContext);
//
//			HostnameVerifier hostnameVerifier = new MySSLHostnameVerifier();
//			httpClientBuilder.setSSLHostnameVerifier(hostnameVerifier);
//
//			HttpClient httpClient = httpClientBuilder.build();
//			HttpPost post = new HttpPost("http://www.sumapay.com/Refund_do");
//
//			post.setEntity(new UrlEncodedFormEntity(nvps, "GBK"));
//
//			CloseableHttpResponse responsePost = (CloseableHttpResponse) httpClient.execute(post);
//			int status = responsePost.getStatusLine().getStatusCode();
//			System.out.println(status);
//			byte[] responseBody = null;
//			String responseBody1 = "";
//			Map<String, Object> resultMap;
//			if (status != HttpStatus.SC_OK) {
//				// TODO 请求失败，进行相应业务处理
//				response.getOutputStream().write(("请求失败，http返回值：" + status).getBytes("GBK"));
//				return;
//			} else {
//				// 获取返回值
//				String result = EntityUtils.toString(responsePost.getEntity(), "GBK");
//				String result2 = EntityUtils.toString(post.getEntity(), "GBK");
//				System.out.println(result2 + "=result");
//				resultMap = JSON.parseObject(result, HashMap.class);
//				post.releaseConnection();
//			}
//			System.out.println(resultMap + "=resultMap");
//
//			String returnRequestId = (String) resultMap.get("requestId");
//			String result = (String) resultMap.get("result");
//
//			String returnSignature = (String) resultMap.get("resultSignature");
//
//			StringBuilder returnSb = new StringBuilder();
//
//			returnSb.append(requestId);
//			returnSb.append(result);
//			returnSb.append(remark);
//			System.out.println(mersignature);
//			String returnSignStr = returnSb.toString();
//			String signature2 = MD5Tools.Md5(returnSb.toString(), merKey);
//			String signCheck;
//
//			if (signature2.equals(returnSignature)) {
//				signCheck = "验签成功";
//			} else {
//				signCheck = "验签失败";
//			}
//
//			com.quickpay.model.AliPayModel aliPayModel = new com.quickpay.model.AliPayModel();
//
//			aliPayModel.setRequestId(returnRequestId);
//			aliPayModel.setResult(result);
//			aliPayModel.setRemark(remark);
//			aliPayModel.setReturnSignature(returnSignature);
//
//			request.getSession().setAttribute("aliPayModel", aliPayModel);
//			response.sendRedirect("IZZ5000.jsp");
//
//			out.flush();
//			out.close();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	@Override
//	public void init() throws ServletException {
//		// Put your code here
//	}
//
//}
